package de.dfki.asr.genesis2.sms.oauth;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.FacebookApi;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.oauth.OAuthService;

/**
 * Servlet implementation class RequestSigner
 */
@WebServlet("/RequestSigner")
public class RequestSigner extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private OAuthService service = null;   
	
    protected static final String FACEBOOK_ACCESS_TOKEN_SESSION = "FACEBOOK_ACCESS_TOKEN_SESSION";
    protected static final String redirect_uri = "http://localhost:8080/sms/FacebookOAuthService";
    protected static final String client_id = "400240100000830";
	protected static final String client_secret = "7c46a4fd701e7b0b122e3885c41f8373";
	protected static final String callback_url = "http://localhost:8080/Test/TestFacebookServlet";
	protected static final String accessToken_url = "https://graph.facebook.com/oauth/access_token?";
	protected static final String requestCode_url = "https://www.facebook.com/dialog/oauth/?";
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RequestSigner() {
        super();
        service = new ServiceBuilder()
        .provider(FacebookApi.class)
        .callback(callback_url)
        .apiKey(client_id)
        .apiSecret(client_secret)
        .build();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		OAuthRequest req = new OAuthRequest(Verb.GET, "https://graph.facebook.com/me/home?with=location");
		String access_token = "AAAFsBCj8RD4BAMJvuzWhD2DkcXoFzDvauds0xoZBRMX8373abuMrGGwyLwajqXAUw8Hhft8gyOXLePCj425fGA8tkayVziXLybyNiRQZDZD";
		Token accessToken = new Token(access_token, client_secret);
	    service.signRequest(accessToken, req);
	    System.out.println(req.getUrl());
	    response.sendRedirect(req.getUrl());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
